function isPassword(name){
	const newPasswordInput = document.getElementById(name);
	const password = newPasswordInput.value;
	let reg = /^(?![0-9]*$)(?![A-z]*$)[0-9A-z]{8,16}$/;
	if (reg.test(password)){
		newPasswordInput.style.border = '2px solid green'
		return true;
	}else{
		newPasswordInput.style.border = '2px solid red';
		return false;
	}
}
function twoIsOnePassword()
{
	const newPasswordInput = document.getElementById('newPassword1').value;
	const newPasswordInput2 = document.getElementById('newPassword2').value;
	if(newPasswordInput != newPasswordInput2)
	{
		return false;
	}
	else
	{
		return true;
	}
}
window.onload = function ()
{
	document.getElementById("newPassword1").onblur = isPassword("newPassword1");
	document.getElementById("newPassword2").onblur = isPassword("newPassword2");
	document.getElementById("submit").onclick = submitClick1;
}
new Vue({
	el: "#manager",
	data: {
		number: "",
		oldPassword: "",
		newPassword1: "",
		newPassword2: ""
	},
	methods: {},
	setUp() {
		let url = "";
		let xhr = new XMLHttpRequest();
		xhr.open('get', url, true);
		xhr.onreadystatechange = () => {
			if (xhr.readyState === 4 || xhr.status === 200) {
				console.log(JSON.parse(xhr.responseText))
			}
		}
		xhr.send(null)
	},
})

function submitClick1() {
	if (!isPassword("newPassword1") || !isPassword("newPassword2")) {
		alert("请确认密码格式");
		return;
	}
	if (!twoIsOnePassword()) {
		alert("两次输入不一样")
	}

	var oldPassword = document.getElementById("oldPassword").value;
	var newPassword = document.getElementById("newPassword2").value;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function () {
		if (xhttp.readyState != 4) {
			return;
		}

		alert(this.responseText);

		if (this.getResponseHeader("href") != null) {
			window.location.href = this.getResponseHeader("href");
		}
	};
	xhttp.open("post", "/super/ChangeSuperServlet?oldPassword="
		+ oldPassword
		+ "&newPassword=" + newPassword
		, true);
	xhttp.send();
}



